<?php
declare (strict_types = 1);

namespace app\api\controller\store;

use app\api\controller\Base;
use app\common\service\store\CommentService;

class GoodsComment extends Base
{
    /**
     * Author:Zhongyuan Lu
     * 商品评价
     * @return mixed|void
     */
    public function comment()
    {
        if (!$this->request->isPost()) {
            return $this->result([], 400, '请求方式错误');
        }

        $params = $this->request->post();
        $params['uid'] = $this->request->uid;

        $this->validateFail(\app\validate\GoodsComment::class,$params);

        if ($params['goods_id'] < 1 || $params['oid'] < 1) {
            return $this->result([], 400, '参数错误');
        }

        $data = CommentService::comment($params);

        return $this->res($data);
    }

    /**
     * Author:Zhongyuan Lu
     * 商品评论点赞
     * @return mixed|void
     */
    public function commentLike()
    {
        if (!$this->request->isGet()) {
            return $this->result([], 400, '请求方式错误');
        }

        $params['comment_id'] = $this->request->get('comment_id',0,'int');

        if (empty($params['comment_id']) || $params['comment_id'] < 1) {
            return $this->result([], 400, '参数错误');
        }
        $params['uid'] = $this->request->uid;

        $data = CommentService::commentLike($params);

        return $this->res($data);
    }
}
